package com.Policing.Adapter;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.Policing.R;
import com.Policing.Since_case.Since_case;
import com.Policing.bean.AddRepairs_bean;

import java.util.List;

/**
 * Created by Administrator on 2019/5/10.
 */

public class Addrepairs_Adapter extends ArrayAdapter {
    private Dialog dialog;
    public Addrepairs_Adapter(Context context, int resource, List<AddRepairs_bean> objects) {

        super(context, resource, objects);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final AddRepairs_bean linkeMain = (AddRepairs_bean)getItem(position);
        final View view = LayoutInflater.from(getContext()).inflate(R.layout.addrepairs_item, null);
        TextView Category_tv = (TextView) view.findViewById(R.id.Category_tv);
        ImageView Asset_img = (ImageView)view.findViewById(R.id.Asset_img);
        TextView Asset_name = (TextView) view.findViewById(R.id.Asset_name);
        TextView Section = (TextView)view.findViewById(R.id.Section);
        TextView Code_number = (TextView)view.findViewById(R.id.Code_number);
        TextView Custodian = (TextView)view.findViewById(R.id.Custodian);
        TextView Model = (TextView)view.findViewById(R.id.Model);
        TextView rfid = (TextView) view.findViewById(R.id.rfid_tv);
        TextView remark = (TextView) view.findViewById(R.id.remark);
        TextView isRemark = (TextView) view.findViewById(R.id.isRemark);
        TextView Category = (TextView)view.findViewById(R.id.Category);
        if(linkeMain.getAsset_img()!=null){
        Asset_img.setImageBitmap(linkeMain.getAsset_img());}
        rfid.setText(linkeMain.getRfid());
        Asset_name.setText(linkeMain.getAsset_name());
        Category_tv.setText(linkeMain.getCategory_tv());
        Section.setText(linkeMain.getSection());
        remark.setText(linkeMain.getRemark());
        if(Since_case.set().getIsRemarks().equals("原因")){
            isRemark.setText("原因");
            Since_case.set().setIsRemarks("备注咯");
        }
        if(Since_case.set().getIsRemarks().equals("故障描述")){
            isRemark.setText("故障描述");
            Since_case.set().setIsRemarks("备注咯");
        }
        Code_number.setText(linkeMain.getCode_number());
        Custodian.setText(linkeMain.getCustodian());
        Model.setText(linkeMain.getModel());
        Category.setText(linkeMain.getCategory());
        Asset_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(linkeMain.getAsset_img()!=null) {
                    //展示在dialog上面的大图
                    dialog = new Dialog(getContext(), R.style.FullActivity);
                    WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
                    attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
                    attributes.height = WindowManager.LayoutParams.MATCH_PARENT;
                    dialog.getWindow().setAttributes(attributes);
                    ImageView imageView = new ImageView(getContext());
                    imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                    imageView.setImageBitmap(linkeMain.getAsset_img());
                    dialog.setContentView(imageView);
                    //大图的点击事件（点击让他消失）
                    dialog.show();
                    imageView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });
                }else {
                    Toast.makeText(getContext(),"暂无图片时无法展示",Toast.LENGTH_SHORT).show();
                }
            }
        });
        return view;
    }
}
